package com.znsd.zl.order.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.znsd.zl.order.entity.OrderEntity;
import com.znsd.zl.order.entity.TradeOrderEntity;
import com.znsd.zl.order.entity.vo.HouseRentVo;
import com.znsd.zl.order.entity.vo.OrderEntityVo;
import com.znsd.zl.order.entity.vo.UserOrderVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @ClassName IOrderDao
 * @Description 订单持久层接口
 * @author jaypdd
 * @email jaypdd@163.com
 * @date 2020-08-16 21:16:34
 * @Version v1.0
 */
@Mapper
public interface IOrderDao extends BaseMapper<OrderEntity> {

	/**
	 * 查询所有订单
	 * @param page
	 * @param map
	 * @return
	 */
	IPage<OrderEntityVo> findAllOrder(Page<OrderEntityVo> page, @Param("map") Map<String,Object> map);

	/**
	 * 查询所有订单app
	 * @param orderEntity
	 * @return
	 */
	List<TradeOrderEntity> findAllTradeOrder(OrderEntity orderEntity);

	/**
	 * 把订单状态改为已完成
	 * @param orderId
	 */
	void setStatusSuccess (Integer orderId);

	/**
	 * 把订单状态改为取消
	 * @param orderId
	 */
	@Update("update t_order set ORDER_STATUS=3 where ID=#{orderId}")
	void setStatusCancel(Integer orderId);

	/**
	 * 添加订单
	 * @param orderEntity
	 */
	void saveOrder(OrderEntity orderEntity);

	/**
	 * 逻辑删除
	 * @param orderId
	 */
	void setIsDelete(Integer orderId);

	/**
	 * 查看用户的租赁
	 * @param userId
	 * @return
	 */
	List<HouseRentVo> findHouseRent(Integer userId);

	/**
	 * 根据订单获取租房记录
	 * @param rentId
	 * @param page
	 * @param limit
	 * @return
	 */
	List<UserOrderVo> orderRent(@Param("rentId") Integer rentId,@Param("page") Integer page,@Param("limit") Integer limit);


	/**
	 * 查询订单出租人数
	 * @param rentId   出租id
	 * @return
	 */
	@Select("select count(1) from t_order where order_status = 1 and rent_id = #{rentId}")
	Integer queryOrderRentAmount(Integer rentId);

	/**
	 * 付款给房东
	 * @param landlordUserId  房东编号
	 * @param money           价格
	 * @return        成功数量
	 */
	Integer userPayment(@Param("landlordUserId") Integer landlordUserId, @Param("money") BigDecimal money);

}
